import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { AreaEntity } from './area.entity';
import { Between, Not, TreeRepository, getManager } from 'typeorm';
import * as dayjs from 'dayjs';
// import { skip } from 'rxjs/operators';
type captcha = {
  key: string;
  captcha: string;
  validTime?: string;
};

@Injectable()
export class AreaService {
  constructor(
    @InjectRepository(AreaEntity)
    private readonly areaRepository: Repository<AreaEntity>,
  ) {}
  async getAreaList(param) {
    return await this.areaRepository.find({ where: param });
  }

  
  async getAreaTree(param) {
    const manager = getManager();

    const root = new AreaEntity();

    root.id = 1;
    // // await manager.save(a1);

    // const a11 = new AreaEntity();
    // a11.name = '北京测试';
    // a11.parent = root;
    // await manager.save(a11);

    return await manager.getTreeRepository(AreaEntity).findDescendantsTree(root);
  }
}
